<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <script type="text/javascript" src="../../inc/ctx.jsp"></script>
        <script type="text/javascript" src="../js/g.js"></script>
        <script type="text/javascript" src="../js/channeltype.js"></script>
        <link href="../css/com.css" type="text/css" rel="stylesheet"/>
        <style>
            b.b1{display:block;padding:1px 5px 1px 5px;border:1px solid #E0E0E0;}
        </style>
    </head>
    <body>
        <div id="panel">
            <form id="queryFrm">
                <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="trhd">
                        <td colspan="3"><h3 class="s1">HotWord查询</h3></td>
                        <td width="8%">&nbsp;</td>
                        <td colspan="4">&nbsp;</td>
                    </tr>
                    <tr>
                        <td width="2%" height="34">&nbsp;</td>
                        <td width="7%" class="r">排序范围：</td>
                        <td width="19%">从
                            <input name="beginOrd" type="text" id="beginOrd"  style="width:50px;" value="" size="18"/>
                            到
                            <input name="endOrd" type="text" id="endOrd"  style="width:50px;" value="" size="18"/></td>
                        <td class="r">发布时间：</td>
                        <td width="26%">
                            从 <input type="text" id="pubBeginTime" name="pubBeginTime" value="" maxlength="19" style="width:100px;" onclick="cdpn('pubBeginTime');"/>
                            到 <input type="text" id="pubEndTime" name="pubEndTime" value="" maxlength="19" style="width:100px;"  onclick="cdpn('pubEndTime');"/>
                        </td>
                        <td width="10%" class="r">ID：</td>
                        <td colspan="2"><input type="text" id="id" name="id" value=""  style="width:120px;"  onClick="this.value=''"/></td>
                    </tr>
                    <tr>
                        <td height="33">&nbsp;</td>
                        <td class="r">查看次数：</td>
                        <td>从
                            <input name="beginHitNum" type="text" id="beginHitNum"  style="width:50px;" value="" size="18"/>
                            到
                            <input name="endHitNum" type="text" id="endHitNum"  style="width:50px;" value="" size="18"/></td>
                        <td class="r">截止时间：</td>
                        <td>从
                            <input type="text" id="stopBeginTime" name="stopBeginTime" value="" maxlength="19" style="width:100px;" onclick="cdpn('stopBeginTime');"/>
                            到
                            <input type="text" id="stopEndTime" name="stopEndTime" value="" maxlength="19" style="width:100px;"  onclick="cdpn('stopEndTime');"/></td>
                        <td class="r">每页显示：</td>
                        <td colspan="2"><select name="listsize" id="listsize">
                                <option value="10">10条</option>
                                <option value="20">20条</option>
                                <option value="50">50条</option>
                            </select></td>
                    </tr>
                    <tr>
                        <td height="33">&nbsp;</td>
                        <td class="r">发布时间：</td>
                        <td><input type="text" id="pubtime" name="pubtime" value="" maxlength="19" style="width:100px;" onClick="cdpn('pubtime');"/>
                            <input onClick="Word.updatePubTime();" type="button" id="updateBtn6" value="更新"></td>
                        <td class="r">板块类别：</td>
                        <td><script>out_select('channeltype');</script></td>
                        <td class="r">Word词搜索：</td>
                        <td colspan="2"><input id="word" name="word" value="" maxlength="32" style="width:120px;" onClick="this.value=''"/></td>
                    </tr>
                    <tr>
                        <td height="33">&nbsp;</td>
                        <td class="r">截止时间：</td>
                        <td><input type="text" id="stoptime" name="stoptime" value="" maxlength="19" style="width:100px;" onClick="cdpn('stoptime');"/>
                            <input onClick="Word.updateStopTime();" type="button" id="updateBtn7" value="更新"></td>
                        <td class="r">信息类别：</td>
                        <td>
                            <input type="hidden" name="cid" id="cid" value=""/>
                            ctp:
                            <input type="text" name="ctp" id="ctp" value="" style="width:50px;" readonly="readonly"  onClick="selectCatelogs();"/>
                            <input type="button" value="清空" onClick="$('#cid').val('');$('#ctp').val('');"/>
                            <input onClick="Word.updateCatalog();" type="button" id="updateBtn3" value="更新类别"></td>
                        <td class="r">&nbsp;</td>
                        <td width="16%"><span class="r">
                                <input onClick="Word.list(1, 0);" type="button" class="button small orange" id="submitBtn" value="Φ 查询">
                                <input onClick="Word.del();" type="button" class="button small gray" id="delBtn" value="x 删除">
                            </span></td>
                        <td width="12%"><input name="rownum" id="rownum" value="" type="hidden" />
                            <input name="crow" id="crow" value="" type="hidden" />
                            <input name="currpage" id="currpage" value="" type="hidden" /></td>
                    </tr>
                </table>
            </form>
        </div>


        <div class="databox">
            <table border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <th width="4%">&nbsp;<a href="javascript:ut.swapsel('sel');">反选</a></th>
                    <th width="13%">WORD </th>
                    <th width="11%">ID/CTP</th>
                    <th width="14%">发布/截止时间时间</th>
                    <th width="28%">GOTOURL</th>
                    <th width="10%">查看次数</th>
                    <th width="10%">排序号</th>
                    <th width="10%">操作</th>
                </tr>
                <tbody class="tbchg" id="datalist"></tbody>
            </table>
        </div>
        <div class="page" id="page"></div>

        <div style="display:block;clear:both;width:98%;height:50px;">&nbsp;</div>





        <!-- 数据处理 -->
        <script id="listTpl" type="text/html">
            {%  for(var k in list){ var e = list[k]; %}
        <tr>
            <td><input name="sel" type="checkbox" value="{%=e.id%}"/></td>
            <td><input id="word{%=e.id%}" value="{%=e.word%}" type="text" maxlength="30"  size="20"/></td>
            <td> {%=e.id%}<br/>{%=e.ctp%}</td>
            <td>{%=highlightNextTime(e.pubtime)%} /<br/>{%=highlightOverTime(e.stoptime)%} </td>
            <td><input id="gotourl{%=e.id%}" value="{%=e.gotourl%}" type="text" maxlength="512" size="45"/> </td>
            <td>{%=e.hitnum%} </td>
            <td><input id="ordernum{%=e.id%}" value="{%=e.ordernum%}" type="text" maxlength="17"  size="8" onchange="Word.updateOrderNum('{%=e.id%}', this.value);"/> </td>
            <td><a href="javascript:;" onclick="Word.save('{%=e.id%}');">保存</a> <a href="javascript:;" onclick="Word.view('{%=e.id%}','{%=e.gotourl%}');">查看</a></td>
        </tr>
        {% } %}
    </script>

    <script type="text/javascript">
        var $lsout = $('#datalist');
        var $ls = $('#listsize');
        var $rownum = $('#rownum');
        var $crow=$('#crow');
        var $curpage=$('#currpage');
        var Word={
            list:function(pgno,r){
                var ls = parseInt($ls.val());
                var step =10;
                var cr = (ls * ( pgno - 1 ));
                $rownum.val(r);
                $crow.val(cr);
                $curpage.val(pgno);
                var params = ut.getFormData('#queryFrm');
                params._t=ut.r();
                $.get('../app/hotword/list_factor.shtm',params,function(d){
                    var x = d;
                    rn=x.rownum;
                    $rownum.val(rn);
                    if(rn>0){
                        ut.outpage(pgno, rn, 'Word.list','page', ls, step);
                        $lsout.html(template.render('listTpl',x));
                    }else{
                        $lsout.html('<tr><td colspan="9">暂无数据.</td></tr>');
                        $('#page').html('');
                    }
                }
            );
            },
            del:function(){
                var ida = ut.getselv('sel');
                if(va.isnull(ida)){ut.m('请选择需要删除的信息.');return;}
                if(!window.confirm("确定删除么?执行后不可恢复."))return;
                $.get('../app/hotword/delete_batch.shtm?t='+ut.r(), "ids="+ida, function(x){
                    var r = $.trim(x);
                    if(va.tint(r)){
                        ut.m('删除成功.已删除记录数为'+r);
                        Word.list($curpage.val(),0);
                    }else{
                        ut.m('删除失败. '+r);
                    }
                });
            },
            updatePubTime:function(){
                var ida = ut.getselv('sel');
                if(va.isnull(ida)){ut.m('请选择需要更新的信息.');return;}
                var t  = $('#pubtime').val();
                if(!va.datetime(t)){ut.m('请选择发布时间！');return;}
                var p = {'ids':ida,'pubtime':ut.parseMs(t)};
                $.get('../app/hotword/update_pubtime.shtm',$.param(p), function(x){
                    var r = $.trim(x);
                    if(va.tint(r)){
                        ut.m('更新成功.已更新记录数为'+r);
                        Word.list($curpage.val(),0);
                    }else{
                        ut.m('更新失败. '+r);
                    }
                });
            },
            updateOrderNum:function(id,w){
                if(!va.isint(w) || w<=0){return;}
                var p={'id':id,'ordernum':w};
                $.get('../app/hotword/update_ordernum.shtm',$.param(p), function(x){
                    var r = $.trim(x);
                    if(r=='ok'){
                        TxBox.wait('更新成功！');
                    }else{
                        TxBox.wait('更新失败！');
                    }
                    TxBox.hide();
                });
            },
            updateStopTime:function(){
                var ida = ut.getselv('sel');
                if(va.isnull(ida)){ut.m('请选择需要更新的信息.');return;}
                var t  = $('#stoptime').val();
                if(!va.datetime(t)){ut.m('请选择截止时间！');return;}
                var p = {'ids':ida,'stoptime':ut.parseMs(t)};
                $.get('../app/hotword/update_stoptime.shtm',$.param(p), function(x){
                    var r = $.trim(x);
                    if(va.tint(r)){
                        ut.m('更新成功.已更新记录数为'+r);
                        Word.list($curpage.val(),0);
                    }else{
                        ut.m('更新失败. '+r);
                    }
                });
            },
            updateCatalog:function(){
                var ida = ut.getselv('sel');
                if(va.isnull(ida)){ut.m('请选择需要更新的信息.');return;}
                var cid = $('#cid').val();
                var ctp = $('#ctp').val();
                if(!va.isint(cid)){ut.m('请选择信息类别.');return;}
                var p = {'ids':ida, 'cid':cid, 'ctp':ctp};
                $.get('../app/hotword/update_catelog.shtm',$.param(p), function(x){
                    var r = $.trim(x);
                    if(va.tint(r)){
                        ut.m('更新成功.已更新记录数为'+r);
                        Word.list($curpage.val(),0);
                    }else{
                        ut.m('更新失败. '+r);
                    }
                });   
            },
            save:function(id){
                var p ={
                    'id':id,
                    'word':$('#word'+id).val(),
                    'gotourl':$('#gotourl'+id).val(),
                    't':ut.r()
                };
                $.post('../app/hotword/update.shtm',$.param(p),function(x){
                    var r = $.trim(x);
                    if(r=='ok'){
                        TxBox.wait('更新成功！');
                    }else{
                        TxBox.wait('更新失败！');
                    }
                    TxBox.hide();
                });
            },
            view:function(id,url){
                window.open(url);
            }
        };

        function selectCatelogs(){
            var ct = $('#channeltype').val();
            if(!va.mint(ct)){
                TxBox.alert('请先选择板块.');
                return;
            }
            TxBox.winpop(250,350,'类目选择', 'catalogs_select_pop.html?channeltype='+ct);
        };

        function reloadCatData(cid,ctp){
            $('#cid').val(cid);
            $('#ctp').val(ctp);
            $('#ctp_name_path').text(cid+';'+ctp);
            TxBox.closeWinpop();
        };
        var g_curTime = (new Date()).getTime();
        // 将过期的信息时间标注为高亮
        function highlightOverTime(t){
            var timeStr = ut.parseDate(t,16);
            if(t>1000 && (Number(t)-g_curTime)<0){
                return '<span style="color:red">'+timeStr+'</span>';
            }
            return timeStr;
        };
        function highlightNextTime(t){
            var timeStr = ut.parseDate(t,16);
            if(t>1000 && (Number(t)-g_curTime)>0){
                return '<span style="color:blue">'+timeStr+'</span>';
            }
            return timeStr;
        };
        
        template.helper('highlightNextTime',highlightNextTime);
        template.helper('highlightOverTime',highlightOverTime);
            
        jQuery(function(){
            $('#channeltype').val('3').attr('readonly','readonly');
            $('#channeltype').change(function(){
                $('#cid').val('');
                $('#ctp').val('');
                if($('#channeltype').val()!='3'){
                    $('#channeltype').val('3');
                }
            });
        });
    </script>
</body>
</html>
